#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N=2e5;
#define INF 0x7fffffff
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//
int l1,r1,l2,r2;
void solve()
{
	sd(l1);sd(r1);sd(l2);sd(r2);
	//int mx=max(l1,l2);
	if(r2<l1||r1<l2)//区间不重叠
	{
		pd(l1+l2);
	}
	else//区间重叠
	{
		pd(max(l1,l2));
	}
	puts("");

}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}